<? 
	if(isset($_POST['btnClear']))
	{
		require("required/dbconnect.php");
		unset($_SESSION['view_history']);
	
		header("Location:os_view_history.php");
	}
	
	
	$title="My Wish List";
	require("required/dbconnect.php");
	require("required/share_function.php");
	require("required/header.php"); 
	
	

	

?>

			
				<table width="100%" cellpadding="6" cellspacing="0">
					<td align="left" class="page_title_bar" width="100%">
					 View History
					</td>
					
					<tr>
						<Td height="300" valign="top"><font class="page_description">Previously viewed</font><br>
                        <form action="<?= $_SERVER['PHP_SELF'] ?>" method="post"  onsubmit="return checkfields(this);">
                     
							<table width="100%">
							<?
								if(empty($_SESSION['view_history']))
								{
							?>
								<tr>
									<td align="center"> :: NO RECORD :: </td>
								</tr>
							<?	
								}
								else
								{
									$tr1="";
									$tr2="";

							?>
							<script>
							function checkfields(frm)
							{
								if(confirm("Confirm to clear the list?"))
								return true;
								else
								return false;
							}
							
							</script>
							<tr>
								<td>
                                  <input type="submit" value="Clear List" class="button" name="btnClear"  />
                                  <br /><br />
                                	<table width="100%" bgcolor="#CCCCCC" cellpadding="1" cellspacing="1">
                                        <tr class='table_header' align="center">
                                           <td width="39%">Product</td><td width="17%">Product code</td>
                                            <td width="22%">View Time</td>
                                        </tr>
										<?
                                            $no=0;
											
											

                                            foreach($_SESSION['view_history'] as $historyItems)
                                            {
												$proId=$historyItems['id'];
												
                                                $get_product=mysql_query("select * from os_products where id=$proId");
                                                $a=mysql_fetch_array($get_product,MYSQL_ASSOC);
                                                
                                                $get_pic=mysql_query("select * from os_productpic where product_id=".$a['id']." order by order_id asc limit 1")or die(mysql_error());
                            
                                                if(mysql_num_rows($get_pic)==0)
                                                {
                                                    $pic="empty";
                                                    $piclink="noimage.jpg";
                                                    $fix="";
                                                }
                                                else
                                                {
                                                    $pic=mysql_fetch_array($get_pic,MYSQL_ASSOC);
                                                    
                                                    $piclink=$pic['name'];
                                                    
                                                    if($pic["width"]-$pic["height"]>0)
                                                    {
                                                        $fix="width=155";
                                                    }
                                                    else
                                                    {
                                                        $fix="height=130";
                                                    }
                                                }	
                                                                                        
                                                if($no%2==0)
                                                {
                                                    $class1="table_item_even";
                                                    $class2="table_item_odd";
                                                }
                                                else
                                                {
                                                    $class1="table_item_odd";
                                                    $class2="table_item_even";
                                                }					
                                                
                                                                                        
                                    	?>
                                         <tr height="30" valign="top" class="<?= $class1 ?>"  onmouseover="this.className='table_item_mouseover'" onmouseout="this.className='<?= $class1 ?>'" align="center">
                                           
                                            <td align="center">
                                                <table width="80%" cellpadding="5" align="center">
                                                    <Td width="12%">
                                                        <a href="os_view_full.php?id=<?= $a['id'] ?>"><img border=0 src="productpic/thumbnails/<?= $piclink ?>" <?= $fix ?>></a>
                                                    </Td>
                                                    <td width="88%" valign="top">
                                                        <a href="os_view_full.php?id=<?= $a['id'] ?>"><?= $a['product_name_eng'] ?></a><br>
                                                        
                                                    </td>
                                                </table>
                                            </td>
                                    
                                  
                                    <td><?= $a['product_code'] ?></td>
                                    <td><?= date("Y-m-d H:m:s",$historyItems['time']); ?></td>
								</tr>
							<? 
								$no++;	
									} 
							?>
							<?= $tr2 ?>
							
							
							</table></td>
							</tr>
							<tr>
							<td colspan="4"><input type="submit" value="Clear List" class="button" name="btnClear"></td>
							</tr>
							
							<?
								}
							?>
							</table>
							</form>
						</Td>
					</tr>		  
			  	</table>
			
<? require("required/footer.php"); ?>	